package ys.demo1.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ys.demo1.config.AliYunProperties;
import ys.demo1.pojo.User;
import ys.demo1.service.UserService;

@RestController
@RequestMapping("/hello")
public class HelloController {

    @Autowired
    private User user1;

    @Autowired
    private AliYunProperties aliyun;

    @Autowired
    private Environment environment;

    @Autowired
    private UserService userService;

    //读取自定义配置的第二中方式
    @Value("${aliyun.username}")
    private String username;

    @Value("${aliyun.ip}")
    private String ip;

    @GetMapping("/hi")
    public String hi() {
        return "你好 SpringBoot\n" + user1;
    }

    @GetMapping("/ali")
    public String ali() {
        return aliyun.toString();
    }

    @GetMapping("ali2")
    public String ali2() {
        return username + ":" + ip;
    }

    @GetMapping("/ali3")
    public String ali3(){
        return environment.getProperty("aliyun","username")+":"+environment.getProperty("aliyun","ip");
    }

    @GetMapping("/read")
    public Object read(){
        return userService.findAll();
    }


}
